// pages/brand_v2/brand_v2.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    contentlist: [],
    //more
    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.getContentlist();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {
    if (this.data.isLoadMore) {
      this._getMoreData();
    } else {
      console.log('没有更多数据');
    }
  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  gobrandgoods(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageB/member/category/brandgoods/brandgoods?id=' + id
    });
  },
  getContentlist() {
    let that = this;
    let urlStr = app.getNetAddresss("goods.brand.get-brand");
    app._getNetWork({
      url: urlStr,
      data:{
        page: 1,
        is_recommend: 1
      },
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            total_page: res.data.last_page,
            contentlist: res.data.data
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  //获取更多数据
  _getMoreData() {
    let that = this;
    that.setData({
      isLoadMore: false
    });
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      that.setData({
        page: that.data.page + 1
      });
      let urlStr = app.getNetAddresss('goods.brand.get-brand');
      urlStr += '&page=' + that.data.page;
      app._getNetWork({
        url: urlStr,
        success: function(resdata) {
          var res = resdata.data;
          that.setData({
            isLoadMore: true
          });
          if (res.result == 1) {
            let myData = res.data.data;
            that.setData({
              contentlist: that.data.contentlist.concat(myData)
            });
          } else {
            that.setData({
              page: that.data.page - 1,
              isLoadMore: false
            });
            return;
          }
        },
        fail: function(res) {
          console.log(res.msg);
        }
      });
    }
  },
});
